<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel"
    @ok="handleOk"
    cancelText="关闭"
  >
    <HfPurchaseorderDetailList ref="realForm" :disabled="disableSubmit"></HfPurchaseorderDetailList>
  </j-modal>
</template>

<script>
import HfPurchaseorderDetailList from './HfPurchaseorderDetailList'
import { getAction, httpAction } from '@api/manage'
export default {
  name: 'HfPurchaseOrderDetailListModal',
  components: {
    HfPurchaseorderDetailList
  },
  data() {
    return {
      title: '',
      width: 896,
      visible: false,
      disableSubmit: false,
      selectids: [],
      orderid: '',
      inputid: '',
      url: {
        list: '/purchase/hfPurchaseInput/SaveHfPurchaseinputDetailByMainId'
      }
    }
  },
  methods: {
    open(orderid, inputid) {
      this.visible = true
      this.orderid = orderid
      this.inputid = inputid
      this.$nextTick(() => {
        this.$refs.realForm.openlist(orderid, inputid)
      })
    },
    handleOk() {
      debugger
      this.selectids = this.$refs.realForm.selectedRowKeys
      var ids = ''
      if (this.selectids.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        for (var a = 0; a < this.selectids.length; a++) {
          ids += this.selectids[a] + ','
        }
      }

      let params = {
        ids: ids,
        orderid: this.inputid
      }
      const that = this
      getAction(this.url.list, params)
        .then(res => {
          if (res.success) {
            that.$message.success(res.message)
            this.close()
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
